-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement encode/decode 1inch extension #75
Conversation
d95c6c7
to
a982d2a
Compare
732bd9c
to
023ce6c
Compare
8e17469
to
30bd71f
Compare
|
||
type AddressHalf [addressHalfLength]byte | ||
|
||
func HalfAddressFromAddress(a common.Address) AddressHalf { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly we never modify an address, I think get a slice of bytes will save some allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because AddressHalf
is a static slice of bytes, same as common.Address
. So I decided still keep it.
// Logic is copied from | ||
// https://etherscan.io/address/0xfb2809a5314473e1165f6b58018e20ed8f07b840#code#F23#L140 | ||
// nolint: gomnd | ||
func DecodeAuctionDetails(hexData []byte) (AuctionDetails, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should check input has enough length for decode operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated
points := make([]AuctionPoint, 0) | ||
for len(data) > 0 { | ||
coefficient := new(big.Int).SetBytes(data[:3]).Int64() | ||
delay := new(big.Int).SetBytes(data[3:5]).Int64() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should validate slice access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated
}) | ||
|
||
// nolint: lll | ||
t.Run("decode 2", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should test for bad data decode also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added other test for bad data
return tmp | ||
} | ||
|
||
func encodeInt64ToBytes(n int64, size int) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take a look at math.PaddedBigBytes
and math.U256Bytes
, it may provided same function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have refactored to use math.PaddingBigBytes
function
var customReceiver common.Address | ||
|
||
if resolverFeeEnabled(flags) { | ||
bankFee.SetBytes(data[:4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for index out of range access
|
||
if integratorFeeEnabled(flags) { | ||
integratorFeeRatio := new(big.Int).SetBytes(data[:2]).Int64() | ||
integratorAddress := common.BytesToAddress(data[2:22]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for index out of range access
875e535
to
4e93168
Compare
pkg/oneinch/fusionorder/settlement_post_interaction_data_encode_decode.go
Show resolved
Hide resolved
pkg/oneinch/fusionorder/settlement_post_interaction_data_encode_decode_test.go
Outdated
Show resolved
Hide resolved
4e93168
to
c2cc714
Compare
pkg/oneinch/decode/decode.go
Outdated
return 0, nil, err | ||
} | ||
|
||
return new(big.Int).SetBytes(d).Int64(), remainingData, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use binary.BigEndian.Uint64()
for reading int64
return AuctionDetails{}, fmt.Errorf("next offset: %w", err) | ||
} | ||
|
||
gasBumpEstimate := new(big.Int).SetBytes(offsetData[:3]).Int64() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let use binary.BigEndian.Uint64()
for reading int value <= 64 bit
pkg/oneinch/limitorder/extension.go
Outdated
|
||
offsetsBytes := e.getOffsets() | ||
paddedOffsetHex := fmt.Sprintf("%064x", offsetsBytes) | ||
return zx + paddedOffsetHex + hex.EncodeToString(interactionsConcatenated) + hex.EncodeToString(e.CustomData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should combine into []byte and use hexutil.Encode once.
8457df1
to
d520732
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
No description provided.